/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.system.renovation.web;

import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.exception.UILayerException;
import com.ce.pms.system.renovation.service.ICheckConfirmItemConfigService;
import com.ce.pms.system.renovation.vo.CheckConfirmItemConfigVO;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：进场确认ACTION<br>
 * @author 易贤建 创建日期：2008-12-24<br>
 */
public class EnterItemAction extends PmsBaseAction {
	/**
	 * 进场确认项目
	 */
	private ICheckConfirmItemConfigService checkConfirmItemConfigService = null;
	/**
	 * 功能描述:初始化列表页面<br>
	 * @param searchVO
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String initList(@Read SearchVO searchVO,
						   @Read(key = "ec_crd",defaultValue="10")	int pageSize,
			               @Read(key = "ec_p", defaultValue="1")	int pageNo){
		searchVO.setPageSize(pageSize);
		searchVO.setPageNo(pageNo);

		Page page = checkConfirmItemConfigService.queryCheckConfirmItemList(searchVO);
		setAttribute("checkConfirmItems", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		return "list";
	}
	/**
	 * 功能描述:初始化添加页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String initAdd(){
		return "add";
	}
	/**
	 * 功能描述:初始化修改页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String initEdit(@Read(key="keyword")Long keyword){
		CheckConfirmItemConfigVO configVO = checkConfirmItemConfigService.findById(keyword);
		setAttribute("configVO", configVO);
		return "edit";
	}
	/**
	 * 功能描述:添加<br>
	 * @param configVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String add(@Read CheckConfirmItemConfigVO configVO){
		configVO.setCreator(super.getUserId());
		checkConfirmItemConfigService.add(configVO);
		processOption(); //处理按钮类型
		return "result";
	}
	/**
	 * 功能描述:修改<br>
	 * @param configVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String edit(@Read CheckConfirmItemConfigVO configVO){
		configVO.setModifier(super.getUserId());
		checkConfirmItemConfigService.edit(configVO);
		processOption(); //处理按钮类型
		return "result";
	}
	/**
	 * 功能描述:删除<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public void delete(@Read(key="keyword")Long keyword){
		try{
			checkConfirmItemConfigService.delete(keyword);
		}catch(BusinessException exception){
			throw exception;
		}catch(Exception exception){
			throw new UILayerException("system:approval_delete_is_reference");
		}
	}
	public void validateItemName(@Read CheckConfirmItemConfigVO configVO){
		try{
			checkConfirmItemConfigService.validateItemName(configVO);
			super.renderText("true");
		}catch(BusinessException exception){
			String errorMessage = exception.getMessage();
			super.renderText(super.getLocaleMessage(errorMessage));
		}
	}
	/**
	 * 功能描述: 处理页面传过来的按钮类型,页面有保存并新增、保存按钮,页面有按钮类型隐藏表单域<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	private void processOption(){
		String option = getRequest().getParameter("option");
		setAttribute("option", option);
	}
	public void setCheckConfirmItemConfigService(
			ICheckConfirmItemConfigService checkConfirmItemConfigService) {
		this.checkConfirmItemConfigService = checkConfirmItemConfigService;
	}
}
